package game.efekti;

import util.INIGroup;
import util.Util;
import game.Item;
import game.MagicEffect;
import game.Item.ItemType;

public class EffectFactory {
	private static MagicEffect getStandardSet()
	{
		int a = Util.getRndInt(0, 9);
		switch (a){
		case 0: case 1: case 2: case 3:
			return new AttributePlus();
		case 4:
			return new Leech();
		case 5:
			return new MaxHealth();
		case 6:
			return new MaxMana();
		case 7: case 8: case 9:
			return new AddResistance();
		}
		return null;
	}
	
	private static MagicEffect getWeaponSet()
	{
		int a = Util.getRndInt(0, 10);
		switch (a){
		case 0: case 1: case 2: case 3:
			return new ElementalDamage();
		case 4: case 5:
			return new AttributePlus();
		case 6:
			return new Leech();
		case 7:
			return new MaxHealth();
		case 8:
			return new MaxMana();
		case 9: case 10:
			return new AddResistance();
		}
		return null;
	}
	
	public static MagicEffect getEffectForLevel(Item.ItemType tip, int lvl)
	{
		MagicEffect me = null;
		switch(tip){
		case ARMOR:
			me = getStandardSet();
			break;
		case HELMET:
			me = getStandardSet();
			break;
		case WEAPON:
			me = getWeaponSet();
			break;
		case CHARM:
			me = getStandardSet();
			break;
		case SHIELD:
			me = getStandardSet();
			break;	
		}
		if (me != null) me.generateForLevel(lvl);
		
		return me;
	}
	
	public static MagicEffect loadFromFile(INIGroup g)
	{
		String t = g.getString("Type");
		MagicEffect me = null;
		
		if("AttributePlus".equals(t)) me = new AttributePlus();
		else if("ElementalDamage".equals(t)) me = new ElementalDamage();
		else if("IncHealth".equals(t)) me = new IncHealth();
		else if("IncMana".equals(t)) me = new IncMana();
		else if("Leech".equals(t)) me = new Leech();
		
		if(me != null) me.loadFromFile(g);
		
		return me;
	}
}
